local hx__longwei = fk.CreateSkill{
    name = "hx__longwei",

    tags = {Skill.Compulsory},
}

hx__longwei:addEffect(fk.RoundStart,{
    can_trigger = function (self, event, target, player, data)
      return player:hasSkill(hx__longwei.name) and player:usedSkillTimes("hx__longnu",Player.HistoryGame) == 0
    end,
    on_cost = function (self, event, target, player, data)
      local room = player.room
      local targets = room.alive_players
      local to = room:askToChoosePlayers(player,{targets = targets, min_num = 1, max_num = 1, skill_name = hx__longwei.name, cancelable = true, no_indicate = false, prompt = "#hx__longwei__choose", })
      if #to > 0 then
         event:setCostData(self,to[1].id)
         return true
      end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player,"hx__longwei__turn",event:getCostData(self))
    end,
})

hx__longwei:addEffect(fk.EventTurnChanging,{
    can_refresh = function (self, event, target, player, data)
        return player:hasSkill(hx__longwei.name) and player:getMark("hx__longwei__turn") and player:getMark("hx__longwei__turn") == data.to.id and player:usedSkillTimes("hx__longnu",Player.HistoryGame) == 0
    end,
    on_refresh = function (self, event, target, player, data)
        player.room:setPlayerMark(player,"hx__longwei__turn",0)
        data.skipped = true
        player:gainAnExtraTurn(true,hx__longwei.name)
    end
})

hx__longwei:addEffect(fk.PreTurnStart,{
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(hx__longwei.name) and target and target ~= player and player:usedSkillTimes("hx__longnu",Player.HistoryGame) > 0
        and target:insideExtraTurn()
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        data.turn_end = true
        player:gainAnExtraTurn(true,hx__longwei.name)
    end,
})

hx__longwei:addEffect(fk.EventPhaseChanging,{
    can_trigger = function (self, event, target, player, data)
         return player:hasSkill(hx__longwei.name) and target and target ~= player and player:usedSkillTimes("hx__longnu",Player.HistoryGame) > 0
         and data.reason ~= "game_rule"
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        player:gainAnExtraPhase(data.phase,hx__longwei.name,true)
        data.skipped = true
    end,
})

return hx__longwei